home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / rcs55.zip / RCSSYN.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  19KB  |  753 lines

  1. /*
  2.  *                     RCS file input
  3.  */
  4. /*********************************************************************************
  5.  *                       Syntax Analysis.
  6.  *                       Keyword table
  7.  *                       Testprogram: define SYNTEST
  8.  *                       Compatibility with Release 2: define COMPAT2=1
  9.  *********************************************************************************
  10.  */
  11.  
  12. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  13.    Copyright 1990 by Paul Eggert
  14.    Distributed under license by the Free Software Foundation, Inc.
  15.  
  16. This file is part of RCS.
  17.  
  18. RCS is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 1, or (at your option)
  21. any later version.
  22.  
  23. RCS is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. GNU General Public License for more details.
  27.  
  28. You should have received a copy of the GNU General Public License
  29. along with RCS; see the file COPYING.  If not, write to
  30. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  
  32. Report problems and direct all questions to:
  33.  
  34.     rcs-bugs@cs.purdue.edu
  35.  
  36. */
  37.  
  38.  
  39. /* $Log: rcssyn.c%v $
  40.  * Revision 1.2  1991/08/23  13:37:43  SGP
  41.  * Ported to MSDOS using Borland C++
  42.  *
  43.  * Revision 5.4  1990/11/01  05:28:48  eggert
  44.  * When ignoring unknown phrases, copy them to the output RCS file.
  45.  * Permit arbitrary data in logs and comment leaders.
  46.  * Don't check for nontext on initial checkin.
  47.  *
  48.  * Revision 5.3  1990/09/20  07:58:32  eggert
  49.  * Remove the test for non-text bytes; it caused more pain than it cured.
  50.  *
  51.  * Revision 5.2  1990/09/04  08:02:30  eggert
  52.  * Parse RCS files with no revisions.
  53.  * Don't strip leading white space from diff commands.  Count RCS lines better.
  54.  *
  55.  * Revision 5.1  1990/08/29  07:14:06  eggert
  56.  * Add -kkvl.  Clean old log messages too.
  57.  *
  58.  * Revision 5.0  1990/08/22  08:13:44  eggert
  59.  * Try to parse future RCS formats without barfing.
  60.  * Add -k.  Don't require final newline.
  61.  * Remove compile-time limits; use malloc instead.
  62.  * Don't output branch keyword if there's no default branch,
  63.  * because RCS version 3 doesn't understand it.
  64.  * Tune.  Remove lint.
  65.  * Add support for ISO 8859.  Ansify and Posixate.
  66.  * Check that a newly checked-in file is acceptable as input to 'diff'.
  67.  * Check diff's output.
  68.  *
  69.  * Revision 4.6  89/05/01  15:13:32  narten
  70.  * changed copyright header to reflect current distribution rules
  71.  * 
  72.  * Revision 4.5  88/08/09  19:13:21  eggert
  73.  * Allow cc -R; remove lint.
  74.  * 
  75.  * Revision 4.4  87/12/18  11:46:16  narten
  76.  * more lint cleanups (Guy Harris)
  77.  * 
  78.  * Revision 4.3  87/10/18  10:39:36  narten
  79.  * Updating version numbers. Changes relative to 1.1 actually relative to
  80.  * 4.1
  81.  * 
  82.  * Revision 1.3  87/09/24  14:00:49  narten
  83.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  84.  * warnings)
  85.  * 
  86.  * Revision 1.2  87/03/27  14:22:40  jenkins
  87.  * Port to suns
  88.  * 
  89.  * Revision 4.1  83/03/28  11:38:49  wft
  90.  * Added parsing and printing of default branch.
  91.  * 
  92.  * Revision 3.6  83/01/15  17:46:50  wft
  93.  * Changed readdelta() to initialize selector and log-pointer.
  94.  * Changed puttree to check for selector==DELETE; putdtext() uses DELNUMFORM.
  95.  *
  96.  * Revision 3.5  82/12/08  21:58:58  wft
  97.  * renamed Commentleader to Commleader.
  98.  *
  99.  * Revision 3.4  82/12/04  13:24:40  wft
  100.  * Added routine gettree(), which updates keeplock after reading the
  101.  * delta tree.
  102.  *
  103.  * Revision 3.3  82/11/28  21:30:11  wft
  104.  * Reading and printing of Suffix removed; version COMPAT2 skips the
  105.  * Suffix for files of release 2 format. Fixed problems with printing nil.
  106.  *
  107.  * Revision 3.2  82/10/18  21:18:25  wft
  108.  * renamed putdeltatext to putdtext.
  109.  *
  110.  * Revision 3.1  82/10/11  19:45:11  wft
  111.  * made sure getc() returns into an integer.
  112.  */
  113.  
  114.  
  115.  
  116. /* version COMPAT2 reads files of the format of release 2 and 3, but
  117.  * generates files of release 3 format. Need not be defined if no
  118.  * old RCS files generated with release 2 exist.
  119.  */
  120. /* version SYNTEST inputs a RCS file and then prints out its internal
  121.  * data structures.
  122. */
  123.  
  124. #include "rcsbase.h"
  125.  
  126. libId(synId, "$Id: rcssyn.c%v 1.2 1991/08/23 13:37:43 SGP Exp $")
  127.  
  128. /* forward */
  129. static const char *getkeyval P((const char*,enum tokens,int));
  130.  
  131. /* keyword table */
  132.  
  133. const char
  134.     Kdesc[]     = "desc",
  135.     Klog[]      = "log",
  136.     Ktext[]     = "text";
  137.  
  138. static const char
  139.     Kaccess[]   = "access",
  140.     Kauthor[]   = "author",
  141.     Kbranch[]   = "branch",
  142.     Kbranches[] = "branches",
  143.     Kcomment[]  = "comment",
  144.     Kdate[]     = "date",
  145.     Kexpand[]   = "expand",
  146.     Khead[]     = "head",
  147.     Klocks[]    = "locks",
  148.     Knext[]     = "next",
  149.     Kstate[]    = "state",
  150.     Kstrict[]   = "strict",
  151. #if COMPAT2
  152.     Ksuffix[]   = "suffix",
  153. #endif
  154.     Ksymbols[]  = "symbols";
  155.  
  156. static struct buf Commleader;
  157. static struct cbuf Ignored;
  158. struct cbuf Comment;
  159. struct access   * AccessList;
  160. struct assoc    * Symbols;
  161. struct lock     * Locks;
  162. int          Expand;
  163. int               StrictLocks;
  164. struct hshentry * Head;
  165. const char      * Dbranch;
  166. int               TotalDeltas;
  167.  
  168.  
  169.     static void
  170. getsemi(const char *key)
  171. /* Get a semicolon to finish off a phrase started by KEY.  */
  172. {
  173.     if (!getlex(SEMI))
  174.         fatserror("missing ';' after '%s'", key);
  175. }
  176.  
  177.     static struct hshentry *
  178. getdnum()
  179. /* Get a delta number.  */
  180. {
  181.     register struct hshentry *delta = getnum();
  182.     if (delta && countnumflds(delta->num)&1)
  183.         fatserror("%s isn't a delta number", delta->num);
  184.     return delta;
  185. }
  186.  
  187.  
  188.     void
  189. getadmin()
  190. /* Read an <admin> and initialize the appropriate global variables.  */
  191. {
  192.     register const char *id;
  193.         struct access   * newaccess;
  194.         struct assoc    * newassoc;
  195.         struct lock     * newlock;
  196.         struct hshentry * delta;
  197.     struct access **LastAccess;
  198.     struct assoc **LastSymbol;
  199.     struct lock **LastLock;
  200.     struct buf b;
  201.     struct cbuf cb;
  202.  
  203.         TotalDeltas=0;
  204.  
  205.     getkey(Khead);
  206.     Head = getdnum();
  207.     getsemi(Khead);
  208.  
  209.     Dbranch = nil;
  210.     if (getkeyopt(Kbranch)) {
  211.         if ((delta = getnum()))
  212.             Dbranch = delta->num;
  213.         getsemi(Kbranch);
  214.         }
  215.  
  216.  
  217. #if COMPAT2
  218.         /* read suffix. Only in release 2 format */
  219.     if (getkeyopt(Ksuffix)) {
  220.                 if (nexttok==STRING) {
  221.             readstring(); nextlex(); /* Throw away the suffix.  */
  222.         } else if (nexttok==ID) {
  223.                         nextlex();
  224.                 }
  225.         getsemi(Ksuffix);
  226.         }
  227. #endif
  228.  
  229.     getkey(Kaccess);
  230.     LastAccess = &AccessList;
  231.         while (id=getid()) {
  232.         newaccess = ftalloc(struct access);
  233.                 newaccess->login = id;
  234.         *LastAccess = newaccess;
  235.         LastAccess = &newaccess->nextaccess;
  236.         }
  237.     *LastAccess = nil;
  238.     getsemi(Kaccess);
  239.  
  240.     getkey(Ksymbols);
  241.     LastSymbol = &Symbols;
  242.         while (id = getid()) {
  243.                 if (!getlex(COLON))
  244.             fatserror("missing ':' in symbolic name definition");
  245.                 if (!(delta=getnum())) {
  246.             fatserror("missing number in symbolic name definition");
  247.                 } else { /*add new pair to association list*/
  248.             newassoc = ftalloc(struct assoc);
  249.                         newassoc->symbol=id;
  250.             newassoc->num = delta->num;
  251.             *LastSymbol = newassoc;
  252.             LastSymbol = &newassoc->nextassoc;
  253.                 }
  254.         }
  255.     *LastSymbol = nil;
  256.     getsemi(Ksymbols);
  257.  
  258.     getkey(Klocks);
  259.     LastLock = &Locks;
  260.         while (id = getid()) {
  261.                 if (!getlex(COLON))
  262.             fatserror("missing ':' in lock");
  263.         if (!(delta=getdnum())) {
  264.             fatserror("missing number in lock");
  265.                 } else { /*add new pair to lock list*/
  266.             newlock = ftalloc(struct lock);
  267.                         newlock->login=id;
  268.                         newlock->delta=delta;
  269.             *LastLock = newlock;
  270.             LastLock = &newlock->nextlock;
  271.                 }
  272.         }
  273.     *LastLock = nil;
  274.     getsemi(Klocks);
  275.  
  276.     if ((StrictLocks = getkeyopt(Kstrict)))
  277.         getsemi(Kstrict);
  278.  
  279.     Comment.size = 0;
  280.     if (getkeyopt(Kcomment)) {
  281.         if (nexttok==STRING) {
  282.             Comment = savestring(&Commleader);
  283.             nextlex();
  284.         }
  285.         getsemi(Kcomment);
  286.         }
  287.  
  288.     Expand = KEYVAL_EXPAND;
  289.     if (getkeyopt(Kexpand)) {
  290.         if (nexttok==STRING) {
  291.             bufautobegin(&b);
  292.             cb = savestring(&b);
  293.             if ((Expand = str2expmode(cb.string)) < 0)
  294.                 fatserror("unknown expand mode %s", b.string);
  295.             bufautoend(&b);
  296.             nextlex();
  297.         }
  298.         getsemi(Kexpand);
  299.         }
  300.     Ignored = getphrases(Kdesc);
  301. }
  302.  
  303. const char *const expand_names[] = {
  304.     /* These must agree with *_EXPAND in rcsbase.h.  */
  305.     "kv","kvl","k","v","o",
  306.     0
  307. };
  308.  
  309.     int
  310. str2expmode(const char *s)
  311. /* Yield expand mode corresponding to S, or -1 if bad.  */
  312. {
  313.     const char *const *p;
  314.  
  315.     for (p = expand_names;  *p;  ++p)
  316.         if (strcmp(*p,s) == 0)
  317.             return p - expand_names;
  318.     return -1;
  319. }
  320.  
  321.  
  322.     void
  323. ignorephrase()
  324. /* Ignore a phrase introduced by a later version of RCS.  */
  325. {
  326.     warnignore();
  327.     hshenter=false;
  328.     for (;;) {
  329.         switch (nexttok) {
  330.         case SEMI: hshenter=true; nextlex(); return;
  331.         case ID:
  332.         case NUM: ffree1(NextString); break;
  333.         case STRING: readstring(); break;
  334.         default: break;
  335.         }
  336.         nextlex();
  337.     }
  338. }
  339.  
  340.  
  341.     static int
  342. getdelta()
  343. /* Function: reads a delta block.
  344.  * returns false if the current block does not start with a number.
  345.  */
  346. {
  347.         register struct hshentry * Delta, * num;
  348.     struct branchhead **LastBranch, *NewBranch;
  349.  
  350.     if (!(Delta = getdnum()))
  351.         return false;
  352.  
  353.         hshenter = false; /*Don't enter dates into hashtable*/
  354.         Delta->date = getkeyval(Kdate, NUM, false);
  355.         hshenter=true;    /*reset hshenter for revision numbers.*/
  356.  
  357.         Delta->author = getkeyval(Kauthor, ID, false);
  358.  
  359.         Delta->state = getkeyval(Kstate, ID, true);
  360.  
  361.     getkey(Kbranches);
  362.     LastBranch = &Delta->branches;
  363.     while ((num = getdnum())) {
  364.         NewBranch = ftalloc(struct branchhead);
  365.                 NewBranch->hsh = num;
  366.         *LastBranch = NewBranch;
  367.         LastBranch = &NewBranch->nextbranch;
  368.         }
  369.     *LastBranch = nil;
  370.     getsemi(Kbranches);
  371.  
  372.     getkey(Knext);
  373.     Delta->next = num = getdnum();
  374.     getsemi(Knext);
  375.     Delta->lockedby = nil;
  376.     Delta->selector = true;
  377.     Delta->ig = getphrases(Kdesc);
  378.         TotalDeltas++;
  379.         return (true);
  380. }
  381.  
  382.  
  383.     void
  384. gettree()
  385. /* Function: Reads in the delta tree with getdelta(), then
  386.  * updates the lockedby fields.
  387.  */
  388. {
  389.     const struct lock *currlock;
  390.  
  391.         while (getdelta());
  392.         currlock=Locks;
  393.         while (currlock) {
  394.                 currlock->delta->lockedby = currlock->login;
  395.                 currlock = currlock->nextlock;
  396.         }
  397. }
  398.  
  399.  
  400.     void
  401. getdesc(int prdesc)
  402. /* Function: read in descriptive text
  403.  * nexttok is not advanced afterwards.
  404.  * If prdesc is set, the text is printed to stdout.
  405.  */
  406. {
  407.  
  408.     getkeystring(Kdesc);
  409.         if (prdesc)
  410.                 printstring();  /*echo string*/
  411.         else    readstring();   /*skip string*/
  412. }
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.     static const char *
  420. getkeyval(const char *keyword, enum tokens token, int optional)
  421. /* reads a pair of the form
  422.  * <keyword> <token> ;
  423.  * where token is one of <id> or <num>. optional indicates whether
  424.  * <token> is optional. A pointer to
  425.  * the actual character string of <id> or <num> is returned.
  426.  */
  427. {
  428.     register const char *val = nil;
  429.  
  430.     getkey(keyword);
  431.         if (nexttok==token) {
  432.                 val = NextString;
  433.                 nextlex();
  434.         } else {
  435.         if (!optional)
  436.             fatserror("missing %s", keyword);
  437.         }
  438.     getsemi(keyword);
  439.         return(val);
  440. }
  441.  
  442.  
  443.  
  444.  
  445.     void
  446. putadmin(register FILE *fout)
  447. /* Function: Print the <admin> node read with getadmin() to file fout.
  448.  * Assumption: Variables AccessList, Symbols, Locks, StrictLocks,
  449.  * and Head have been set.
  450.  */
  451. {
  452.     const struct assoc *curassoc;
  453.     const struct lock *curlock;
  454.     const struct access *curaccess;
  455.     register const char *sp;
  456.     register size_t ss;
  457.  
  458.     aprintf(fout, "%s\t%s;\n", Khead, Head?Head->num:"");
  459.     if (Dbranch && VERSION(4)<=RCSversion)
  460.         aprintf(fout, "%s\t%s;\n", Kbranch, Dbranch);
  461.  
  462.     aputs(Kaccess, fout);
  463.         curaccess = AccessList;
  464.         while (curaccess) {
  465.            aprintf(fout, "\n\t%s", curaccess->login);
  466.                curaccess = curaccess->nextaccess;
  467.         }
  468.     aprintf(fout, ";\n%s", Ksymbols);
  469.         curassoc = Symbols;
  470.         while (curassoc) {
  471.            aprintf(fout, "\n\t%s:%s", curassoc->symbol, curassoc->num);
  472.                curassoc = curassoc->nextassoc;
  473.         }
  474.     aprintf(fout, ";\n%s", Klocks);
  475.         curlock = Locks;
  476.         while (curlock) {
  477.            aprintf(fout, "\n\t%s:%s", curlock->login, curlock->delta->num);
  478.                curlock = curlock->nextlock;
  479.         }
  480.     if (StrictLocks) aprintf(fout, "; %s", Kstrict);
  481.     aprintf(fout, ";\n");
  482.     if ((ss = Comment.size)) {
  483.         aprintf(fout, "%s\t%c", Kcomment, SDELIM);
  484.         sp = Comment.string;
  485.         do {
  486.             if (*sp == SDELIM)
  487.             afputc(SDELIM,fout);
  488.             afputc(*sp++,fout);
  489.         } while (--ss);
  490.         aprintf(fout, "%c;\n", SDELIM);
  491.         }
  492.     if (Expand != KEYVAL_EXPAND)
  493.         aprintf(fout, "%s\t%c%s%c;\n",
  494.             Kexpand, SDELIM, expand_names[Expand], SDELIM
  495.         );
  496.     awrite(Ignored.string, Ignored.size, fout);
  497.     aputc('\n', fout);
  498. }
  499.  
  500.  
  501.  
  502.  
  503.     static void
  504. putdelta(register const struct hshentry *node,register FILE *fout)
  505. /* Function: prints a <delta> node to fout;
  506.  */
  507. {
  508.     const struct branchhead *nextbranch;
  509.  
  510.         if (node == nil) return;
  511.  
  512.     aprintf(fout, "\n%s\n%s\t%s;\t%s %s;\t%s %s;\nbranches",
  513.         node->num,
  514.         Kdate, node->date,
  515.         Kauthor, node->author,
  516.         Kstate, node->state?node->state:""
  517.     );
  518.         nextbranch = node->branches;
  519.         while (nextbranch) {
  520.            aprintf(fout, "\n\t%s", nextbranch->hsh->num);
  521.                nextbranch = nextbranch->nextbranch;
  522.         }
  523.  
  524.     aprintf(fout, ";\n%s\t%s;\n", Knext, node->next?node->next->num:"");
  525.     awrite(node->ig.string, node->ig.size, fout);
  526. }
  527.  
  528.  
  529.  
  530.  
  531.     void
  532. puttree(const struct hshentry *root,register FILE *fout)
  533. /* Function: prints the delta tree in preorder to fout, starting with root.
  534.  */
  535. {
  536.     const struct branchhead *nextbranch;
  537.  
  538.         if (root==nil) return;
  539.  
  540.     if (root->selector)
  541.         putdelta(root,fout);
  542.  
  543.         puttree(root->next,fout);
  544.  
  545.         nextbranch = root->branches;
  546.         while (nextbranch) {
  547.              puttree(nextbranch->hsh,fout);
  548.              nextbranch = nextbranch->nextbranch;
  549.         }
  550. }
  551.  
  552.  
  553.  
  554. int putdtext(const char *num,
  555.              struct cbuf log,
  556.              const char *srcfilename,
  557.              FILE *fout,
  558.              int diffmt)
  559. /* Function: write a deltatext-node to fout.
  560.  * num points to the deltanumber, log to the logmessage, and
  561.  * sourcefile contains the text. Doubles up all SDELIMs in both the
  562.  * log and the text; Makes sure the log message ends in \n.
  563.  * returns false on error.
  564.  * If diffmt is true, also checks that text is valid diff -n output.
  565.  */
  566. {
  567.     FILE *fin;
  568.     int result;
  569.     if (!(fin = fopen(srcfilename,"r"))) {
  570.         eerror(srcfilename);
  571.         return false;
  572.     }
  573.     result = putdftext(num,log,fin,fout,diffmt);
  574.     ffclose(fin);
  575.     return result;
  576. }
  577.  
  578.     int
  579. putdftext(const char *num,
  580.           struct cbuf log,
  581.           register FILE *fin,
  582.           register FILE *fout,
  583.           int diffmt)
  584. /* like putdtext(), except the source file is already open */
  585. {
  586.     register const char *sp;
  587.     register int c;
  588.     register size_t ss;
  589.     int ed;
  590.     struct diffcmd dc;
  591.  
  592.     aprintf(fout,DELNUMFORM,num,Klog);
  593.         /* put log */
  594.     afputc(SDELIM,fout);
  595.     sp = log.string;
  596.     for (ss = log.size;  ss;  --ss) {
  597.         if (*sp == SDELIM)
  598.             aputc(SDELIM,fout);
  599.         aputc(*sp++,fout);
  600.     }
  601.         /* put text */
  602.     aprintf(fout, "\n%c\n%s\n%c",SDELIM,Ktext,SDELIM);
  603.     if (!diffmt) {
  604.         /* Copy the file */
  605.         while ((c=getc(fin))!=EOF) {
  606.         if (c==SDELIM) aputc(SDELIM,fout);   /*double up SDELIM*/
  607.         aputc(c,fout);
  608.         }
  609.     } else {
  610.         initdiffcmd(&dc);
  611.         while (0  <=  (ed = getdiffcmd(fin,EOF,fout,&dc)))
  612.         if (ed)
  613.             while (dc.nlines--)
  614.             do {
  615.                 if ((c=getc(fin)) == EOF) {
  616.                 if (!dc.nlines)
  617.                     goto OK_EOF;
  618.                 faterror("unexpected EOF in diff output");
  619.                 }
  620.                 if (c==SDELIM) aputc(SDELIM,fout);
  621.                 aputc(c,fout);
  622.             } while (c != '\n');
  623.     }
  624.     OK_EOF:
  625.     aprintf(fout, "%c\n", SDELIM);
  626.     return true;
  627. }
  628.  
  629.     void
  630. initdiffcmd(register struct diffcmd *dc)
  631. /* Initialize *dc suitably for getdiffcmd(). */
  632. {
  633.     dc->adprev = 0;
  634.     dc->dafter = 0;
  635. }
  636.  
  637.     int
  638. getdiffcmd(register FILE *fin,
  639.            int delimiter,
  640.            register FILE *fout,
  641.            struct diffcmd *dc)
  642. /* Get a editing command output by 'diff -n' from fin.
  643.  * The input is delimited by the delimiter, which may be EOF for no delimiter.
  644.  * Copy a clean version of the command to fout (if nonnull).
  645.  * Yield 0 for 'd', 1 for 'a', and -1 for EOF.
  646.  * Store the command's line number and length into dc->line1 and dc->nlines.
  647.  * Keep dc->adprev and dc->dafter up to date.
  648.  */
  649. {
  650.     register int c;
  651.     register char *p;
  652.     unsigned long line1, nlines;
  653.     char buf[BUFSIZ];
  654.     c = getc(fin);
  655.     if (c==delimiter) {
  656.         if (c!=EOF && fout)
  657.             aputc(c, fout);
  658.         return EOF;
  659.     }
  660.     p = buf;
  661.     do {
  662.         if (c == EOF) {
  663.             faterror("unexpected EOF in diff output");
  664.         }
  665.         if (buf+BUFSIZ-2 <= p) {
  666.             faterror("diff output command line too long");
  667.         }
  668.         *p++ = c;
  669.     } while ((c=getc(fin)) != '\n');
  670.     if (delimiter!=EOF)
  671.         ++rcsline;
  672.     *p = '\0';
  673.     for (p = buf+1;  *p++ == ' ';)
  674.         ;
  675.     --p;
  676.     if (!((buf[0]=='a' || buf[0]=='d')  &&  isdigit(*p))) {
  677.         faterror("bad diff output: %s", buf);
  678.     }
  679.     line1 = 0;
  680.     do {
  681.         line1 = line1*10 + (*p++ - '0');
  682.     } while (isdigit(*p));
  683.     while (*p++ == ' ')
  684.         ;
  685.     --p;
  686.     nlines = 0;
  687.     while (isdigit(*p))
  688.         nlines = nlines*10 + (*p++ - '0');
  689.     if (!nlines) {
  690.         faterror("incorrect range %lu in diff output: %s", nlines, buf);
  691.     }
  692.     switch (buf[0]) {
  693.         case 'a':
  694.         if (line1 < dc->adprev) {
  695.             faterror("backward insertion in diff output: %s", buf);
  696.         }
  697.         dc->adprev = line1 + 1;
  698.         break;
  699.         case 'd':
  700.         if (line1 < dc->adprev  ||  line1 < dc->dafter) {
  701.             faterror("backward deletion in diff output: %s", buf);
  702.         }
  703.         dc->adprev = line1;
  704.         dc->dafter = line1 + nlines;
  705.         break;
  706.     }
  707.     if (fout) {
  708.         aprintf(fout, "%s\n", buf);
  709.     }
  710.     dc->line1 = line1;
  711.     dc->nlines = nlines;
  712.     return buf[0] == 'a';
  713. }
  714.  
  715.  
  716.  
  717. #ifdef SYNTEST
  718.  
  719. const char cmdid[] = "syntest";
  720.  
  721.     int
  722. main(int argc,char *argv[])
  723. {
  724.  
  725.         if (argc<2) {
  726.         aputs("No input file\n",stderr);
  727.         exitmain(EXIT_FAILURE);
  728.         }
  729.         if ((finptr=fopen(argv[1], "r")) == NULL) {
  730.         faterror("can't open input file %s", argv[1]);
  731.         }
  732.         Lexinit();
  733.         getadmin();
  734.         putadmin(stdout);
  735.  
  736.         gettree();
  737.         puttree(Head,stdout);
  738.  
  739.         getdesc(true);
  740.  
  741.         if (nextlex(),nexttok!=EOFILE) {
  742.         fatserror("expecting EOF");
  743.         }
  744.     exitmain(EXIT_SUCCESS);
  745. }
  746.  
  747.  
  748. exiting void exiterr() { _exit(EXIT_FAILURE); }
  749.  
  750.  
  751. #endif
  752.  
  753.